package com.ken;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class FirstServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");

        System.out.println("客户端 POST请求name:" + name);
        response.setContentType("text/html;charset = utf-8");
        PrintWriter out = response.getWriter();

        out.println("<h3> Hello World! </h3>");
//        out.println("<h3>" + name + "你好!!!</h3>");
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");

        System.out.println("客户端 GET请求 name:" + name);
        response.setContentType("text/html;charset = utf-8");
        PrintWriter out = response.getWriter();

        out.println("<h3> Hello World! </h3>");
//        out.println("<h3>" + name + "你好!!!</h3>");
        out.close();

    }
}
